/*
 * @Author: 肖思汗 
 * @Date: 2025-09-26 08:53:08 
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2025-09-26 09:03:58
 */


//mesh
import { FrontSide, MeshStandardMaterial } from 'three';
import MeshBase from "three-base/MeshBase";
import warehouseGLB from "./warehouse.glb?url";
import publicMaterial from '../publicMaterial';
import utils from '@/utils/utils';
import Transition from 'three-base/Transition';

// 库房
export default class Warehouse extends MeshBase {

    constructor() {
        super();
        this.loadModel(warehouseGLB).then(() => {

            this.traverseMesh((mesh) => {

                // 开发环境下，添加点击事件
                if (utils.isDev) {
                    mesh.userData = {
                        cursor: "pointer",
                        enableEvent: true,
                    };
                    mesh.addEventListener("dbclick", e => {
                        console.log(mesh.name);
                        //@ts-ignore
                        console.log(e.point);
                        utils.editorMaterial(mesh.material as MeshStandardMaterial);
                    });
                }

                if (mesh.name === "db2002") {
                    // 材质设置成单面
                    (mesh.material as MeshStandardMaterial).side = FrontSide;
                }

                // name: "db2001" 这个要隐藏
                if (mesh.name === "db2001") {
                    mesh.visible = false;
                }

                // publicMaterial 透明蓝色材质 name: "网格008" 和 "db2003"
                if ([
                    "网格008", "db2003", "db2", "网格006", "网格006_1", "网格006_2", "网格088",
                    "网格008_1", "网格008_2", "网格088_2"

                ].includes(mesh.name)) {
                    (mesh.material as any) = publicMaterial.transparentBlue;
                }

            })

        });
    }

    //档案柜动画
    canbinetTransition = (() => {
        const transition = new Transition({ x: 0 }); // 0.6
        transition.setDuration(3000);
        transition.setBezier([0, 0, 1, 1]);
        transition.onChange(({ x }) => {
            this.traverseMesh((mesh) => {
                if (
                    ["网格069_1", "网格016", "pCube524002", "网格016_1", "nb1_dangangui3002"].includes(mesh.name)
                ) {
                    mesh.position.x = x;
                }
            });

        });
        return transition;
    })();



}
